<?php
/*
 *      osdictionary.php
 *      
 *      Copyright 2010 Vitaliy Rakitin <virak@ukr.net>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

//require_once($_SERVER['DOCUMENT_ROOT']."/classes/System/osobject.php");

//require_once($_SERVER['DOCUMENT_ROOT']."/classes/System/oslistform.php");
//require_once($_SERVER['DOCUMENT_ROOT']."/classes/System/ositemform.php");
//require_once($_SERVER['DOCUMENT_ROOT']."/classes/System/oschoiceform.php");
require_once($_SERVER['DOCUMENT_ROOT']."/classes/System/ositems.php");
//require_once($_SERVER['DOCUMENT_ROOT']."/classes/System/osmetafields.php");
//require_once($_SERVER['DOCUMENT_ROOT']."/classes/System/ostables.php");
 
class osdictionary {

	//private $uuid;
	//private $object;
	//protected $type;
	//private $name;
	//private $item;
	//public $orderby = "id";
	//public $direction = "ASC";
	//public $select;
	//private $fields;
	//private $tables;
	//private $forms;
	private $items;
	private $meta;


	function __construct($meta) {
		$this->meta = $meta;
		$this->items = new ositems($this->meta);
		//$this->object = $object;
		//$this->uuid = $uuid;
		//$this->fields = new osmetafields($this);
		//$this->tables = new ostables($this->uuid, $this->item);
		
		//$this->item = $item;
		//$this->type = get_class($this);

/*
		$sql = "SELECT * FROM objects WHERE id = '".$this->uuid."';";
		$result = DB::select($sql);
		if (isset($result[0])) {
			$this->name = $result[0]["name"];
		}
*/
	}

/*
	function itemform($item) {
		return new ositemform($this, $this->items->byuuid($item));
	}
*/

	function __get($name) {
		switch ($name) {
			//case "items": { if (!$this->items) { return new ositems($this->meta);} else {return $this->items;} break;} // Это надо выкинуть из метаданных
			//case "items": { return new ositems($this->meta); break;}
			case "items": { return $this->items; break;}
			//case "fields": { return new osmetafields($this); break;} // Fields of the table
			//case "fields": { return $this->fields; break;} // Fields of the table
			//case "tables": { return new ostables($this->uuid, $this->item); break;} // Tables of the table
			//case "forms": {break;};
			//case "listform": { return new oslistform($this); break;}
			//case "choiceform": { return new oschoiceform($this); break;}
			case "name": { return $this->meta->name;break;}
			//case "uuid": { return $this->uuid;break;}
		}
	}

	function __set($name, $value) {
		switch ($name) {
			//case "name": { $this->name = $value;break;}
		}
	}

/*
	function save() {
		// Check whether there is a item in the database
		$sql = "SELECT * FROM objects WHERE id = '".$this->uuid."';";
		$result = DB::select($sql);
		// if present - then update
		if (isset($result[0])) {
			$action = "UPDATE objects SET";
			$action .= " name = '".$this->name."'";
			$action .= " WHERE id = '".$this->uuid."';";
		} else {
			// else - insert
			$action = "INSERT INTO objects(";
			$action .= " id, owner, name, type)";
			$action .= " VALUES(";
			$action .= " '$this->uuid', '$this->object', '$this->name', '$this->type');";
		}
		echo $action."<br>";
		DB::query($action);
	}
	
	function delete() {
		$action = "DELETE FROM objects";
		//$action .= " name = ".$this->name;
		$action .= " WHERE id = '".$this->uuid."';";
		echo $action."<br>";
		DB::query($action);
		return true;
	}
*/
}
?>
